home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-04-27 | 2.4 KB | 77 lines | [TEXT/????] |
- ;;;; PPA: Piecewise polynomial approximations
-
- ;;; To make a piecewise polynomial approximation of a function, f,
- ;;; we specify the range, [low, high], the maximum order of polynomial
- ;;; that fits may be made with, and the accuracy required.
-
- (define (make-ppa f low high max-order accuracy)
- (let* ((c (/ (+ low high) 2))
- (d (/ (- high low) 2))
- (g (lambda (x) (f (+ x c))))
- (result (get-poly-and-errors g (- d) d max-order))
- (p (car result))
- (eps (cadr result)))
- (if (< eps accuracy)
- (ppa-make-from-poly low high
- (cheb-econ p low high (- accuracy eps)))
- (let ((mid (/ (+ low high) 2)))
- (ppa-adjoin (make-ppa f low mid max-order accuracy)
- (make-ppa f mid high max-order accuracy))))))
-
-
- ;;; PPA-VALUE will evaluate a PPA at any given point, x.
-
- (define (ppa-value ppa x)
- (define (ppa-search low high body)
- (cond ((ppa-terminal? body)
- (poly-value (ppa-poly body) (- x (/ (+ low high) 2))))
- ((ppa-split? body)
- (let ((s (ppa-split body)))
- (if (< x s)
- (ppa-search low s (ppa-low-side body))
- (ppa-search s high (ppa-high-side body)))))
- (else (error "Bad body -- PPA-SEARCH"))))
- (let ((low (ppa-low-bound ppa))
- (high (ppa-high-bound ppa)))
- (if (and (<= low x) (<= x high))
- (ppa-search low high (ppa-body ppa))
- (error "Out of bounds -- PPA-VALUE"))))
-
-
- ;;; We may use PPAs to memoize functions.
-
- (define (ppa-memo f low high max-order accuracy)
- (let ((ppa (make-ppa f low high max-order accuracy)))
- (lambda (x) (ppa-value ppa x))))
-
- ;;; Implementation of PPA data structures
-
- (define (ppa-make-from-poly low high poly)
- (cons (cons low high)
- (cons 'ppa-terminal poly)))
-
- (define (ppa-adjoin ppalow ppahigh)
- (if (= (cdar ppalow) (caar ppahigh))
- (cons (cons (caar ppalow) (cdar ppahigh))
- (cons 'ppa-split
- (cons (cdar ppalow)
- (cons (cdr ppalow) (cdr ppahigh)))))
- (error "PPAs not adjacent -- PPA-ADJOIN")))
-
- (define ppa-low-bound caar)
- (define ppa-high-bound cdar)
-
- (define ppa-body cdr)
-
- (define (ppa-terminal? b)
- (eq? (car b) 'ppa-terminal))
- (define ppa-poly cdr)
-
-
- (define (ppa-split? b)
- (eq? (car b) 'ppa-split))
-
- (define ppa-split cadr)
- (define ppa-low-side caddr)
- (define ppa-high-side cdddr)
-